package com.itheima.zuoye.zuoye7;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class Test {
//    1. 获取当前的日期,并把这个日期转换为指定格式的字符串,如 2088-08-08 08:08:0
        public static void main(String[] args) throws ParseException {
            Date date = new Date();
            System.out.println(date);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String format = sdf.format(date);
            System.out.println(format);

            System.out.println("=============");
            LocalDateTime now = LocalDateTime.now();
            System.out.println(now);
            DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            String format1 = dtf.format(now);
            String format2 = now.format(dtf);
            System.out.println("1.8以后"+format1);
            System.out.println("1.8以后"+format2);



            System.out.println("=============");
            String time = "2023-03-26";
            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
            Date parse = sdf1.parse(time);
            System.out.println(parse);

            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy年MM月dd日");
            String format3 = sdf2.format(parse);
            System.out.println(format3);

            System.out.println("=============");
            DateTimeFormatter dtf1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy年MM月dd日");
            LocalDate parse1 = LocalDate.parse(time, dtf1);
            System.out.println(parse1);
            String format4 = parse1.format(dtf2);
            //String format5 = dtf2.format(parse1);
            System.out.println(format4);
            //System.out.println(format5);

        }
    }



